<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>keypress demo</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    $(document).keypress(function(e) {
        if (e.which == 32 || (65 <= e.which && e.which <= 65 + 25)
                          || (97 <= e.which && e.which <= 97 + 25)) {
        var c = String.fromCharCode(e.which);
        $("p").append($("<span/>"))
              .children(":last")
              .append(document.createTextNode(c));
      } else if (e.which == 8) {
        // backspace in IE only be on keydown
        $("p").children(":last").remove();
      }
      $("div").text(e.which);
    });
</script>
</head>

<body>
    <p></p>
    
    <div></div>
</body>

</html>